﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using DLL.Entities;
using DLL;

namespace RAD
{
    public partial class RAD : Form
    {
        public RAD()
        {
            InitializeComponent();
        }

        string cwd = System.IO.Directory.GetCurrentDirectory();

        private void btn_launch_Click(object sender, EventArgs e)
        {

            if (rad_birds.Checked)
            {
                txtBox_Alt.Text = Convert.ToString(Utility.RandomNumber(20, 100));
                txtBox_Dist.Text = Convert.ToString(Utility.RandomNumber(100, 1000));
                txtBox_Speed.Text = Convert.ToString(Utility.RandomNumber(5, 30));
                txtBox_TL.Text = "1";
                btn_scan.Enabled = false;
                rad_birds.Enabled = true;
                rad_dragon.Enabled = false;
                rad_mis.Enabled = false;
                rad_jet.Enabled = false;
            }
            else if (rad_mis.Checked)
            {
                txtBox_Alt.Text = Convert.ToString(Utility.RandomNumber(10000, 20000));
                txtBox_Dist.Text = Convert.ToString(Utility.RandomNumber(20000, 25000));
                txtBox_Speed.Text = Convert.ToString(Utility.RandomNumber(500, 600));
                txtBox_TL.Text = "4";
                btn_scan.Enabled = false;
                rad_birds.Enabled = false;
                rad_dragon.Enabled = false;
                rad_mis.Enabled = true;
                rad_jet.Enabled = false;
            }
            else if (rad_jet.Checked)
            {
                txtBox_Alt.Text = Convert.ToString(Utility.RandomNumber(20000, 25000));
                txtBox_Dist.Text = Convert.ToString(Utility.RandomNumber(20000, 25000));
                txtBox_Speed.Text = Convert.ToString(Utility.RandomNumber(2000, 2500));
                txtBox_TL.Text = "4";
                btn_scan.Enabled = false;
                rad_birds.Enabled = false;
                rad_dragon.Enabled = false;
                rad_mis.Enabled = false;
                rad_jet.Enabled = false;
                
            }
            else if (rad_dragon.Checked)
            {
                txtBox_Alt.Text = Convert.ToString(Utility.RandomNumber(100, 2000));
                txtBox_Dist.Text = Convert.ToString(Utility.RandomNumber(10000, 15000));
                txtBox_Speed.Text = Convert.ToString(Utility.RandomNumber(100, 250));
                txtBox_TL.Text = "5";
                btn_scan.Enabled = false;
                rad_birds.Enabled = false;
                rad_dragon.Enabled = false;
                rad_mis.Enabled = false;
                rad_jet.Enabled = false;
            }
            else
            {
                MessageBox.Show("Select a target");
            }
            Bogey Bog_Obj = new Bogey();
            if (rad_birds.Checked)
            {
                Bog_Obj.Name = rad_birds.Text;
            }
            if (rad_dragon.Checked)
            {
                Bog_Obj.Name = rad_dragon.Text;
            }
            if (rad_jet.Checked)
            {
                Bog_Obj.Name = rad_jet.Text;
            }
            if (rad_mis.Checked)
            {
                Bog_Obj.Name = rad_mis.Text;
            }
            Bog_Obj.Speed = txtBox_Speed.Text;
            Bog_Obj.Altitude = txtBox_Alt.Text;
            Bog_Obj.Distance = txtBox_Dist.Text;
            Bog_Obj.ThreatLevel = txtBox_TL.Text;

            cwd = cwd.Replace("\\bin\\Debug", "");

            XmlSerializer serializer = new XmlSerializer(typeof(Bogey));
            XMLHandler.WriteXML(Bog_Obj, "Bogey_Serialzed.xml", serializer);
            MessageBox.Show("Lock On Complete");
        }

        private void btn_scan_Click(object sender, EventArgs e)
        {
                    Random randomNumber = new Random();
                    int tempNumber = randomNumber.Next(5);
                    btn_launch.Enabled = true;

                    switch(tempNumber)
                    {
                        case 1:
                        rad_birds.Checked = true;
                        break;
                        case 2:
                        rad_dragon.Checked = true;
                        break;
                        case 3:
                        rad_jet.Checked = true;
                        break;
                        case 4:
                        rad_mis.Checked = true;
                        break;
                    }
                }

        private void timer1_Tick(object sender, EventArgs e)
        {
            RadStatus radStatus = new RadStatus();
            radStatus.radStatus = Convert.ToString(DateTime.Now);
            XmlSerializer serializer = new XmlSerializer(typeof(RadStatus));
            XMLHandler.WriteXML(radStatus, "RadStatus_Serialzed.xml", serializer);
        }
    }
}

